<template>
	<view>
		<u-upload
			:fileList="fileList"
			@afterRead="afterRead"
			@delete="deletePic"
			uploadIcon="plus"
			uploadIconColor="#111"
			name="4"
			multiple
			:maxCount="10"
		></u-upload>
	</view>
</template>

<script>
	export default {
		components: {
			
		},
		data() {
			return {
				fileList: [],
				// apiUrl:this.$config.uni_app_web_api_url
			}
		},
		onShow() {
			
		},
		onPullDownRefresh(){
		
		},
		onLoad() {
			
			
		},
		methods: {
			deletePic(event){
				this.fileList.splice(event.index, 1)
				console.log('eventeventeventevent',event)
				let data = this.fileList.map(e=>e.url).toString()
				this.$emit('input',data)
			},
			async afterRead(event){
				console.log('eventeventevent',event.file[0].url)
				// const result = await this.uploadFilePromise(event.file[0].url)
				const result = await this.$store.dispatch('uploadFilePromise',event.file[0].url)
				this.fileList.push({
					url:result.url
				})
				let data = this.fileList.map(e=>e.url).toString()
				this.$emit('input',data)
				console.log('resultresultresultresult',result)
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					uni.showLoading({
					   title: '加载中'
					});
					let a = uni.uploadFile({
						url: `${this.$config.uni_app_web_api_url}/common/upload/qiniu`, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						// formData: {
						// 	user: 'test'
						// },
						success: (res) => {
							setTimeout(() => {
								let data = JSON.parse(res.data)
								uni.hideLoading();
								resolve(data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style  lang="scss">
	
</style>